<template>
	<view class="main-class">
		<tn-sticky>
			<view class="header-class tn-flex justify-end" >
				<view class="status_bar" style="height: var(--status-bar-height); width: 100%; "></view>			
				<!-- <view class="tn-color-black_text tn-flex justify-between tn-text-xl tn-pl-xl tn-pr-xl tn-pb-xl" >
					<tn-icon name="title" size="1"/>
					<span class="tn-white_text">密码修改</span>
					<tn-icon name="title" size="1" />
				</view> -->
				<view class="navbar-class tn-pb">
					<tn-navbar  height="45px" home-icon="left" back-icon="" :bottom-shadow = "false" bg-color="tn-type-primary_bg" index-url="/pages/login/login"> 地址配置 </tn-navbar>
				</view>
			</view>
		</tn-sticky>
		
		<tn-form label-position="top" class="form-class tn-p">
		  <tn-form-item label="地址:" label-position="left">
		    <tn-input v-model="settingInfo.ip" placeholder="127.0.0.1"/>
		  </tn-form-item>
		  <tn-form-item label="端口:" label-position="left">
		    <tn-input v-model="settingInfo.port" placeholder="9533" />
		  </tn-form-item>
		  <tn-form-item label="前缀:" label-position="left">
		    <tn-input v-model="settingInfo.prefix" placeholder="jnsk"  />
		  </tn-form-item>
		</tn-form>
		<button class="button-class" @click="doSetting"> 保  &ensp; &ensp; 存 </button>
		
	</view>
	
	
</template>

<script setup>
	import { ref,reactive,onMounted } from 'vue'
	import { postNoCall } from '@/api/index.js'
	import { EventBus } from '@/mitt/EventBus.js';
	import { toastMessage } from '@/utils/toast.js'
	import md5 from "js-md5";
	import {createParams} from '@/utils/utils.js'
	const procName = "PROC_APP_DO_REGISTER";
	
	const userInfo = reactive({});
	const settingInfo = reactive({
		ip:"",
		port:"",
		prefix:""
	});
	

	
	onMounted(()=>{
		let httpStr = uni.getStorageSync("HTTP");
		httpStr =  httpStr.replace("http://", "")
		var parts = httpStr.split(/[:/]/);
		var ip = parts[0]; 
		var port = parts[1]; 
		var prefix = parts[2]; 		
		settingInfo.ip = ip;
		settingInfo.port = port;
		settingInfo.prefix = prefix;
		
	})
	
	let doRegister = () =>{
		let params = {};
		params["P_PWD"] = md5(userInfo.password);
		params["P_ACTION"] = "REGIST";
		params["P_PROC_NAME"] = procName;
		postNoCall(Object.assign(params,createParams(userInfo)) ).then(res=>{
			if(res){
				if(res.code === 200 ){
					toastMessage("已提交，请等待审核！");
				}
			}
			
		})
	}
	
	let doSetting = () =>{
		if(!settingInfo.ip){
			toastMessage("地址不允许为空！");
		}
		if(!settingInfo.port){
			toastMessage("端口不允许为空！");
		}
		if(!settingInfo.prefix){
			toastMessage("前缀不允许为空！");
		}
		if(settingInfo.ip && settingInfo.port && settingInfo.prefix){
			let httpStr = "http://"+settingInfo.ip+":"+settingInfo.port+"/"+settingInfo.prefix;
			uni.setStorageSync("HTTP", httpStr);
			toastMessage("保存成功，请返回登陆！");
			uni.navigateTo({
				url: '/pages/login/login'
			});
		}
	}
	
</script>

<style scoped>
.header-class{
	height: 17vh !important;
	flex-direction: column
}
.form-class{
	width: 90vw;
	margin-left: 5vw;
}
.button-class{
	margin-top: 5vh;
	width: 90vw;
	border-radius: 40px !important;
	/* color: #FFFFFF !important; */
	background: linear-gradient(to right, var(--beginColor),var(--endColor)) !important;
	/* border: 0px solid rgba(0, 0, 0, 0.2) !important; */
	color: #FFFFFF;
}

.button-class::after{
	border: 0px solid rgba(0, 0, 0, 0.2) !important;
}

.navbar-class{
	font-size: 20px;
	color: #FFFFFF;
}
</style>
